#pragma once

#ifdef _AFX_PACKING
#pragma pack(push, _AFX_PACKING)
#endif

#ifdef _AFX_MINREBUILD
#pragma component(minrebuild, off)
#endif

struct JPlex
{
	JPlex* pNext;
#ifndef _WIN64
#if (_AFX_PACKING >= 8)
	DWORD dwReserved[1];    // align on 8 byte boundary
#endif
#endif
	// BYTE data[maxNum*elementSize];

	void* data() { return this+1; }

	static JPlex* PASCAL Create(JPlex*& pHead, UINT_PTR nMax, UINT_PTR cbElement)
	{
		_ASSERT(nMax > 0 && cbElement > 0);
		if (nMax == 0 || cbElement == 0)
		{
			throw 0;
		}

		JPlex* p = (JPlex*) new BYTE[sizeof(JPlex) + nMax * cbElement];
		// may throw exception
		p->pNext = pHead;
		pHead = p;  // change head (adds in reverse order for simplicity)
		return p;
	}
	// like 'calloc' but no zero fill
	// may throw memory exceptions

	void FreeDataChain()       // free this one and links
	{
		JPlex* p = this;
		while (p != NULL)
		{
			BYTE* bytes = (BYTE*) p;
			JPlex* pNext = p->pNext;
			delete[] bytes;
			p = pNext;
		}
	}
};

#ifdef _AFX_MINREBUILD
#pragma component(minrebuild, on)
#endif

#ifdef _AFX_PACKING
#pragma pack(pop)
#endif